package org.jeecg.cn.edu.scau.vm.container.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.jeecg.cn.edu.scau.vm.container.domain.VmContainerUsage;

import java.time.LocalDateTime;

@Mapper
public interface VmContainerUsageMapper extends BaseMapper<VmContainerUsage> {
    /**
     * 基于乐观锁机制实现机时更新
     *
     * @param remainingTime 剩余机时
     * @param userId        用户ID
     * @param targetTime    要更新成的时间
     */
    @Update("update vm_container_usage " +
            "set remaining_time = #{targetTime}, " +
            "last_distribution_time = #{last_distribution_time} " +
            "where user_id = #{userId} and remaining_time = #{remainingTime}")
    Integer updateRemainIngTimeSafely(@Param("userId") String userId,
                                      @Param("remainingTime") Integer remainingTime,
                                      @Param("targetTime") Integer targetTime,
                                      @Param("last_distribution_time") LocalDateTime last_distribution_time);

}
